/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-04-23 15:17:33
 * @LastEditors: huangtianyang
 * @LastEditTime: 2023-10-09 17:54:01
 * @FilePath: \cxl-admin\src\pages\finance\invoice\look\index.ts
 */
import { invoiceDetailed, invoiceDo } from '@/apis/finance/invoice'
import router from '@/router'
import { routerStore } from '@/store/router.store'
import { ElMessage } from 'element-plus'
import { reactive, ref } from 'vue'
import { useRoute } from 'vue-router'

export default class InvoiceDetailed {
    //是否是审核
    isAudit = ref(true)
    //申请人=>公司
    name = ref('')
    //发票抬头=>公司
    header = ref('')
    //税号
    ID = ref('')
    //发票金额
    price = ref('')
    //邮箱地址
    email = ref('')
    //手机号码
    phone = ref('')
    //申请时间
    applyTime = ref('')
    //开票订单
    invoiceOrderList: any[] = reactive([])
    _routerStore: any
    invoiceId = ref('')
    constructor() {
        const route = useRoute()
        this._routerStore = routerStore()
        console.log('route', route.query.type as string)
        this.isAudit.value = (route.query.type as string) === 'audit' ? true : false
        this.invoiceId.value = route.query.id as string

        if (this.invoiceId.value) {
            invoiceDetailed(this.invoiceId.value).then(res => {
                if (res.data.value === 200) {
                    this.name.value = res.data.data.companyName
                    this.header.value = res.data.data.invoiceCompany
                    this.phone.value = res.data.data.phone
                    this.ID.value = res.data.data.taxNumber
                    this.price.value = res.data.data.amount
                    this.email.value = res.data.data.email
                    this.applyTime.value = res.data.data.createTime
                    this.invoiceOrderList.length = 0
                    this.invoiceOrderList.push(...res.data.data.reportOrderInfoVos)
                }
            })
        }
    }

    /**
     * 监听点击保存
     */
    onConfirm = () => {
        invoiceDo(this.invoiceId.value).then(res => {
            if (res.data.value === 200) {
                ElMessage.success('开票成功！')
                this.onCancel()
            }
        })
    }
    onCancel = () => {
        this._routerStore.removeHeaderRoute(this._routerStore.selectIndex)
        router.push('/finance/invoice')
    }
}
